<?php
namespace Common\Model;

use Think\Model;


class AnalysisModel extends Model
{
    public function getAnalysisList($condition = array(), $order = "id desc")
    {
        $analysis = $this->where($condition)->order($order)->select();
        return $analysis;
    }

    public function getAnalysis($condition = array())
    {
        $analysis = $this->where($condition)->find();
        return $analysis;
    }

    /**
     * @param int $orders 新订单
     * @param int $trades 新交易额
     * @param int $registers 新注册量
     * @param int $users 新购买用户
     */
    public function addAnalysis($orders = 0, $trades = 0, $registers = 0, $users = 0)
    {
        $today = date("Y-m-d");
        $where["time"] = array("like", $today . "%");
        $analysis = $this->where($where)->find();
        if ($analysis) {
            $this->where(array("id" => $analysis["id"]))->setInc("orders", $orders);
            $this->where(array("id" => $analysis["id"]))->setInc("trades", $trades);
            $this->where(array("id" => $analysis["id"]))->setInc("registers", $registers);
            $this->where(array("id" => $analysis["id"]))->setInc("users", $users);
        } else {
            $this->add(array("orders" => $orders, "trades" => $trades, "registers" => $registers, "users" => $users));
        }
    }
}